package org.example.demosql.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.demosql.ResponseHttps.ResponseData;
import org.example.demosql.SQL.Entity.UserEmail;
import org.example.demosql.SQL.Service.UserEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Tag(name = "用户管理", description = "用户管理相关接口")
@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserEmailService userEmailService;

    @GetMapping("/all")
    @Operation(summary = "查询所有用户")
    public ResponseData getAllUsers() {
        List<UserEmail> users = userEmailService.findAllUsers();
        Map<String, Object> result = new HashMap<>();
        result.put("users", users);
        return new ResponseData("200", "success", true, result);
    }

    // 分页查询
    @GetMapping("/page")
    @Operation(summary = "分页查询用户")
    public ResponseData findUsersByPage(
            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        IPage<UserEmail> result = userEmailService.selectPage(pageNum, pageSize);
        return new ResponseData("200", "success", true, result);
    }
}
